(function(){BX.namespace("BX.rest.integration");if(BX.rest.integration.selector){return}function Selector(t){this.init(t)}Selector.prototype.init=function(t){this.manager=t.manager;this.id=t.id;this.scopeSelectorName=t.scopeSelectorName;this.pathToAdd=t.pathToAdd;this.pathToEdit=t.pathToEdit;this.onChange=t.onChange;this.context=BX(t.containerId);this.signetParameters=t.signetParameters;this.action=t.action;this.mess=t.mess||{searchTitle:""};this.ajaxUses=false;this.initSelector();top.BX.addCustomEvent(top,"rest-integration-edit-change",this.onCampaignChange.bind(this))};Selector.prototype.initSelector=function(){this.selector=BX.UI.TileSelector.getById(this.id);if(!this.selector){throw new Error("Tile selector `"+this.id+"` not found.")}BX.addCustomEvent(this.selector,this.selector.events.buttonSelect,this.onButtonSelect.bind(this));BX.addCustomEvent(this.selector,this.selector.events.buttonSelectFirst,this.onButtonSelectFirst.bind(this));BX.addCustomEvent(this.selector,this.selector.events.buttonAdd,this.onButtonAdd.bind(this));BX.addCustomEvent(this.selector,this.selector.events.tileClick,this.onTileClick.bind(this));BX.addCustomEvent(this.selector,this.selector.events.input,this.onInput.bind(this));BX.addCustomEvent(this.selector,this.selector.events.search,this.onSearch.bind(this));BX.addCustomEvent(this.selector,this.selector.events.tileRemove,this.onTileRemove.bind(this));BX.addCustomEvent(this.selector,this.selector.events.tileAdd,this.onTileAdd.bind(this))};Selector.prototype.onTileAdd=function(tile){if(this.scopeSelectorName!==""){var scopeTile=BX.UI.TileSelector.getById(this.scopeSelectorName);if(!!scopeTile){BX.ajax.runComponentAction("bitrix:rest.integration.selector","getNeededScope",{mode:"class",signedParameters:this.signetParameters,data:{code:tile.id,action:this.action}}).then(function(t){if(t.status==="success"&&typeof t.data=="object"&&t.data.length>0){var e=null;t.data.forEach(function(t){e=scopeTile.getTile(t.id);if(e===null){scopeTile.addTile(t.name,{},t.id)}})}})}}if(this.onChange!==""){eval(this.onChange)}};Selector.prototype.onTileRemove=function(tile){if(this.onChange!==""){eval(this.onChange)}};Selector.prototype.getSearcherData=function(){if(this.ajaxUses===false){var t=this.selector;BX.ajax.runComponentAction("bitrix:rest.integration.selector","get"+this.action,{mode:"class",signedParameters:this.signetParameters}).then(function(e){if(e.status==="success"&&typeof e.data=="object"&&typeof e.data.list=="object"){t.setSearcherData(e.data.list||[])}else{t.hideSearcher.bind(t)}});this.ajaxUses=true}};Selector.prototype.onButtonSelect=function(){this.selector.showSearcher(this.mess.searchTitle)};Selector.prototype.onButtonSelectFirst=function(){this.getSearcherData()};Selector.prototype.onButtonAdd=function(){};Selector.prototype.onTileClick=function(t){this.getSearcherData();this.selector.showSearcher(this.mess.searchTitle)};Selector.prototype.onInput=function(t){};Selector.prototype.onSearch=function(t){};Selector.prototype.fire=function(t,e){e=e||{};BX.onCustomEvent(this,t,e)};Selector.prototype.actualizeTiles=function(t,e){var i=this.selector.getTile(t.id);if(i){this.selector.updateTile(i,t.name,t.data,t.bgcolor,t.color)}else if(e){this.selector.addTile(t.name,t.data,t.id,t.bgcolor,t.color)}};Selector.prototype.actualize=function(t,e){this.selector.clearSearcher();this.actualizeTiles(t,e)};Selector.prototype.onCampaignChange=function(t){this.actualize(t,this.isAdding);this.isAdding=false};function Manager(){}Manager.prototype.create=function(t){return new Selector(t)};BX.rest.integration.selector=Selector;BX.rest.integration.selectorManager=new Manager})(window);
//# sourceMappingURL=script.map.js